package com.ruoyi.web.controller.module.mall.good.controller;

import java.util.List;

import com.ruoyi.web.controller.module.mall.good.domain.MallGood;
import com.ruoyi.web.controller.module.mall.good.service.IMallGoodService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电商的商品(简化版)Controller
 * 
 * @author ruoyi
 * @date 2024-11-12
 */
@Controller
@RequestMapping("/mall/good")
public class MallGoodController extends BaseController
{
    private String prefix = "mall/good";

    @Autowired
    private IMallGoodService mallGoodService;

    @RequiresPermissions("mall:good:view")
    @GetMapping()
    public String good()
    {
        return prefix + "/good";
    }

    /**
     * 查询电商的商品(简化版)列表
     */
    @RequiresPermissions("mall:good:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallGood mallGood)
    {
        startPage();
        List<MallGood> list = mallGoodService.selectMallGoodListV2(mallGood);
        return getDataTable(list);
    }

    /**
     * 导出电商的商品(简化版)列表
     */
    @RequiresPermissions("mall:good:export")
    @Log(title = "电商的商品(简化版)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallGood mallGood)
    {
        List<MallGood> list = mallGoodService.selectMallGoodList(mallGood);
        ExcelUtil<MallGood> util = new ExcelUtil<MallGood>(MallGood.class);
        return util.exportExcel(list, "电商的商品(简化版)数据");
    }

    /**
     * 新增电商的商品(简化版)
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电商的商品(简化版)
     */
    @RequiresPermissions("mall:good:add")
    @Log(title = "电商的商品(简化版)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallGood mallGood)
    {
        return toAjax(mallGoodService.insertMallGood(mallGood));
    }

    /**
     * 修改电商的商品(简化版)
     */
    @RequiresPermissions("mall:good:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MallGood mallGood = mallGoodService.selectMallGoodById(id);
        mmap.put("mallGood", mallGood);
        return prefix + "/edit";
    }

    /**
     * 修改保存电商的商品(简化版)
     */
    @RequiresPermissions("mall:good:edit")
    @Log(title = "电商的商品(简化版)", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallGood mallGood)
    {
        return toAjax(mallGoodService.updateMallGood(mallGood));
    }

    /**
     * 删除电商的商品(简化版)
     */
    @RequiresPermissions("mall:good:remove")
    @Log(title = "电商的商品(简化版)", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallGoodService.deleteMallGoodByIds(ids));
    }
}
